package com.csun.cmny.provider.service.impl;

import com.csun.cmny.base.enums.ErrorCodeEnum;
import com.csun.cmny.provider.exceptions.OmcBizException;
import com.csun.cmny.provider.model.service.UacUserFeignApi;
import com.csun.cmny.provider.model.vo.OpcUserVo;
import com.csun.cmny.provider.model.vo.VolunteerVo;
import com.csun.cmny.provider.service.UacRpcService;
import com.csun.cmny.util.wrapper.Wrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Auther: chisj chisj@foxmal.com
 * @Date: 2019-10-10 13:48
 * @Description: the class uac rpc service impl
 */
@Slf4j
@Service
public class UacRpcServiceImpl implements UacRpcService {

    @Resource
    private UacUserFeignApi uacUserFeignApi;

    /**
     * query opc user vo by user id
     *
     * @param userId the user id
     * @return the opc user vo
     */
    @Override
    public OpcUserVo queryOpcUserVoByUserId(Long userId) {

        try {
            Wrapper<OpcUserVo> wrapper = uacUserFeignApi.queryOpcUserVoByUserId(userId);
            if (wrapper == null) {
                throw new OmcBizException(ErrorCodeEnum.GL99990002);
            }
            if (wrapper.error()) {
                throw new OmcBizException(ErrorCodeEnum.UAC10018002);
            }

            OpcUserVo result = wrapper.getResult();

            assert result != null;

            return result;
        } catch (Exception e) {
            log.error("getVolunteerByVolunteerId={}", e.getMessage(), e);
        }

        return null;
    }
}
